home *** CD-ROM | disk | FTP | other *** search
/ HPAVC / HPAVC CD-ROM.iso / PRUS101.ZIP / FDRIVES.INC < prev    next >
Text File  |  1994-12-19  |  10KB  |  410 lines

  1. { FDRIVES.INC - include file for the PRUSSG unit FDOS to speed up and enhance
  2.   drive related operations under DOS / implementation part }
  3.  (***************************************************************************
  4.  
  5.          RELEASE 1.00 - as first contained in the file PRUS101.LZH
  6.                 by Orazio Czerwenka, 2:2450/540.55, GERMANY
  7.  
  8.                --------------------------------------------
  9.                 organized for Fido's PASCAL related echoes    
  10.                --------------------------------------------
  11.  
  12.      09/06/1994 to --/--/---- by Orazio Czerwenka, 2:2450/540.55, GERMANY
  13.  
  14.  
  15.  
  16.            As far as third party copyrights are not violated this
  17.            source code is hereby placed to the public domain. Use
  18.            it whatever way you want, but use AT YOUR OWN RISK.
  19.  
  20.            In case you should modify the source rather send your
  21.            modifications to the unit's current organizer (see above for
  22.            NM address) than to spread it on your own. This will help to
  23.            keep the unit updated and grant a certain standard to all
  24.            other users as well.
  25.  
  26.            The unit is currently still under work. So it might greatly
  27.            benefit of your participation.
  28.  
  29.            Those who contributed to the following piece of source,
  30.            listed in alphabethical order:
  31.         ================================================================
  32.            Orazio Czerwenka, Andrew Eigus, Peter Schuette ...
  33.         ================================================================
  34.            YOUR NAME WILL APPEAR HERE IF YOU CONTRIBUTE USEFUL SOURCE.
  35.  
  36.            Credits in your own programs are as welcome as unnecessary.
  37.  
  38.          Special thanks to Andrew Eigus (2:5100/33, Latvia) who greatly
  39.           supported this piece of source by contributing a special PD
  40.                          version of his Unit ENHDOS.
  41.  
  42.  ***************************************************************************)
  43.  
  44. { -------------------------------------------------------------------------- }
  45.  
  46. Function GetVerify; assembler;
  47. { Original author: Andrew Eigus }
  48. Asm
  49.   MOV AH,54H
  50.   INT 21h
  51. End; { GetVerify }
  52.  
  53. { -------------------------------------------------------------------------- }
  54.  
  55. Function SetVerify; assembler;
  56. { Original author: Andrew Eigus }
  57. Asm
  58.   CALL GetVerify
  59.   PUSH AX
  60.   MOV AL,Verify
  61.   MOV AH,2EH
  62.   INT 21h
  63.   POP AX
  64. End; { SetVerify }
  65.  
  66. { -------------------------------------------------------------------------- }
  67.  
  68. Function GetCurDisk; assembler;
  69. { Original author: Andrew Eigus }
  70. Asm
  71.   MOV AH,19h
  72.   INT 21h
  73. End; { GetCurDisk }
  74.  
  75. { -------------------------------------------------------------------------- }
  76.  
  77. Function SetCurDisk; assembler;
  78. { Original author: Andrew Eigus }
  79. Asm
  80.   MOV AH,0Eh
  81.   MOV DL,Drive
  82.   INT 21h
  83. End; { SetCurDisk }
  84.  
  85. { -------------------------------------------------------------------------- }
  86.  
  87. Procedure GetDriveAllocInfo; assembler;
  88. { Original author: Andrew Eigus }
  89. Asm
  90.   PUSH DS
  91.   MOV AH,1Ch
  92.   MOV DL,Drive
  93.   INT 21h
  94.   MOV AH,BYTE PTR [DS:BX]
  95.   POP DS
  96.   LES DI,Info
  97.   CLD
  98.   XCHG AH,AL
  99.   STOSB  { store Info.FATId }
  100.   XCHG AX,DX
  101.   STOSW  { store Info.Clusters }
  102.   XCHG AL,DH
  103.   STOSB  { store Info.SectPerClust }
  104.   XCHG AX,CX
  105.   STOSW  { store Info.SectSize }
  106. End; { GetDriveAllocInfo }
  107.  
  108. { -------------------------------------------------------------------------- }
  109.  
  110. Function GetDPB; assembler;
  111. { Original author: Andrew Eigus }
  112. Asm
  113.   MOV DOSResult,dosrOk
  114.   PUSH DS
  115.   MOV AH,32h
  116.   MOV DL,Drive
  117.   INT 21h
  118.   MOV WORD PTR [DPB],DS
  119.   MOV WORD PTR [DPB+2],BX
  120.   POP DS
  121.   XOR AH,AH
  122.   CMP AL,0FFh
  123.   JNE @@1
  124.   MOV DOSResult,dosrInvalidDrive
  125.   PUSH DOSResult
  126.   {$IFOPT G+}
  127.   PUSH fnGetDPB { store function code }
  128.   {$ELSE}
  129.   MOV AX,fnGetDPB
  130.   PUSH AX
  131.   {$ENDIF}
  132.   CALL ErrorHandler
  133.   MOV AX,DOSResult
  134.   NEG AX
  135. @@1:
  136. End; { GetDPB }
  137.  
  138. { -------------------------------------------------------------------------- }
  139.  
  140. Function DiskSize; assembler;
  141. { Original author: Andrew Eigus }
  142. Asm
  143. @@1:
  144.   MOV DOSResult,dosrOk
  145.   MOV AH,36h
  146.   MOV DL,Drive
  147.   INT 21h
  148.   CMP AX,0FFFFh
  149.   JE  @@2
  150.   MOV BX,DX
  151.   IMUL CX
  152.   IMUL BX
  153.   JMP @@3
  154. @@2:
  155.   MOV DOSResult,dosrInvalidDrive
  156.   PUSH DOSResult
  157.   {$IFOPT G+}
  158.   PUSH fnGetDiskSize { store function code }
  159.   {$ELSE}
  160.   MOV AX,fnGetDiskSize
  161.   PUSH AX
  162.   {$ENDIF}
  163.   CALL ErrorHandler
  164.   CMP AL,frRetry
  165.   JE  @@1
  166.   MOV AX,DOSResult
  167.   NEG AX
  168.   XOR DX,DX
  169. @@3:
  170. End; { DiskSize }
  171.  
  172. { -------------------------------------------------------------------------- }
  173.  
  174. Function DiskFree; assembler;
  175. { Original author: Andrew Eigus }
  176. Asm
  177. @@1:
  178.   MOV DOSResult,dosrOk
  179.   MOV AH,36h
  180.   MOV DL,Drive
  181.   INT 21h
  182.   CMP AX,0FFFFh
  183.   JE  @@2
  184.   IMUL CX
  185.   IMUL BX
  186.   JMP @@3
  187. @@2:
  188.   MOV DOSResult,dosrInvalidDrive
  189.   PUSH DOSResult
  190.   {$IFOPT G+}
  191.   PUSH fnGetDiskFree { store function code }
  192.   {$ELSE}
  193.   MOV AX,fnGetDiskFree
  194.   PUSH AX
  195.   {$ENDIF}
  196.   CALL ErrorHandler
  197.   CMP AL,frRetry
  198.   JE  @@1
  199.   MOV AX,DOSResult
  200.   NEG AX
  201.   XOR DX,DX
  202. @@3:
  203. End; { DiskFree }
  204.  
  205. { -------------------------------------------------------------------------- }
  206.  
  207. Function IsFixedDrive; assembler;
  208. { Original author: Andrew Eigus }
  209. Asm
  210.   MOV DOSResult,dosrOk
  211.   MOV AX,4408h
  212.   MOV BL,Drive
  213.   INT 21h
  214.   JNC @@1
  215.   MOV DOSResult,AX { save error code in global variable }
  216.   PUSH AX     { store error code }
  217.   {$IFOPT G+}
  218.   PUSH fnIsFixedDrive { store function code }
  219.   {$ELSE}
  220.   MOV AX,fnIsFixedDrive
  221.   PUSH AX
  222.   {$ENDIF}
  223.   CALL ErrorHandler
  224. @@1:
  225. End; { IsFixedDrive }
  226.  
  227. { -------------------------------------------------------------------------- }
  228.  
  229. Function IsNetworkDrive; assembler;
  230. { Original author: Andrew Eigus }
  231. Asm
  232.   MOV DOSResult,dosrOk
  233.   MOV AX,4409h
  234.   MOV BL,Drive
  235.   INT 21h
  236.   JNC @@1
  237.   MOV DOSResult,AX { save error code in global variable }
  238.   PUSH AX     { store error code }
  239.   {$IFOPT G+}
  240.   PUSH fnIsNetworkDrive { store function code }
  241.   {$ELSE}
  242.   MOV AX,fnIsNetworkDrive
  243.   PUSH AX
  244.   {$ENDIF}
  245.   CALL ErrorHandler
  246. @@1:
  247. End; { IsNetworkDrive }
  248.  
  249. { -------------------------------------------------------------------------- }
  250.  
  251. Function IsCDROMDrive; assembler;
  252. { Original author: Andrew Eigus }
  253. Asm
  254.   MOV AX,1500h
  255.   XOR BX,BX
  256.   INT 2Fh
  257.   XOR CL,CL { MOV CL,False }
  258.   OR  BX,0    { not a best solution, works onley with MSCDEX CD-ROM v2.00+ }
  259.   JZ  @@1
  260.   MOV AX,150Bh
  261.   XOR CH,CH
  262.   MOV CL,Drive
  263.   INT 2Fh
  264.   XOR CL,CL { MOV CL,False }
  265.   CMP BX,0ADADh
  266.   JNE @@1
  267.   OR  AX,0
  268.   JZ  @@1
  269.   INC CL { MOV CL,True }
  270. @@1:
  271.   MOV AL,CL
  272. End; { IsCDROMDrive }
  273.  
  274. { -------------------------------------------------------------------------- }
  275.  
  276. Function IsCompressedDrive; assembler;
  277. { Original author: Andrew Eigus }
  278. Asm
  279.   MOV AX,4A11h
  280.   MOV BX,1
  281.   MOV DL,Drive
  282.   INT 2Fh
  283.   XOR CL,CL { MOV CL,False }
  284.   OR  AX,0  { is DoubleSpace loaded? }
  285.   JNZ @@1
  286.   CMP DL,BL { if a host drive equal to compressed, then get out... }
  287.   JE  @@2
  288.   TEST BL,10000000b { bit 7=1: DL=compressed,BL=host
  289.                            =0: DL=host,BL=compressed }
  290.   JZ  @@2           { so avoid host drives, assume host=fixed :) }
  291.   CMP Drive,DL
  292.   JNE @@2
  293. @@1:
  294.   INC CL { MOV CL,True }
  295. @@2:
  296.   MOV AL,CL
  297. End; { IsCompressedDrive }
  298.  
  299. { -------------------------------------------------------------------------- }
  300.  
  301. Function GetDriveType(Drive : byte) : byte; assembler;
  302. { Original author: Andrew Eigus }
  303. Asm
  304.   CMP Drive,0
  305.   JNE @@1
  306.   CALL GetCurDisk
  307.   MOV Drive,AL
  308.   INC Drive
  309. @@1:
  310.   PUSH WORD PTR Drive
  311.   CALL IsCDROMDrive
  312.   OR  AL,False
  313.   JZ  @@2
  314.   MOV AL,dtCDROM
  315.   JMP @@7
  316. @@2:
  317.   MOV AL,Drive
  318.   DEC AL
  319.   PUSH AX
  320.   CALL IsCompressedDrive
  321.   OR  AL,False
  322.   JZ  @@3
  323.   MOV AL,dtCompressed
  324.   JMP @@7
  325. @@3:
  326.   PUSH WORD PTR Drive
  327.   CALL IsNetworkDrive
  328.   XOR BL,BL  { MOV BL,False }
  329.   CMP DOSResult,dosrOk
  330.   JNE @@6
  331.   OR  AL,False
  332.   JZ  @@4
  333.   MOV AL,dtRemote
  334.   JMP @@7
  335. @@4:
  336.   PUSH WORD PTR Drive
  337.   CALL IsFixedDrive
  338.   XOR BL,BL
  339.   CMP DOSResult,dosrOk
  340.   JNE @@6
  341.   OR  AL,False
  342.   JZ  @@5
  343.   MOV AL,dtFixed
  344.   JMP @@7
  345. @@5:
  346.   MOV BL,dtRemovable
  347. @@6:
  348.   MOV AL,BL
  349. @@7:
  350. End; { GetDriveType }
  351.  
  352. { -------------------------------------------------------------------------- }
  353.  
  354. Function LogicalDrives;
  355. { Mailed in by Peter Schuette }
  356. Const MaxDrives : ARRAY[1..26] Of Char ='ABCDEFGHIJKLMNOPQRSTUVWXYZ';
  357. Var Regs : Registers;
  358.     i : Byte;
  359.     Drives : String[26];
  360. Begin {LogicalDrives}
  361.   Drives := '';
  362.  
  363.   For i := 1 To 26 Do Begin
  364.     Regs.AH := $44;  {DOS function $44}
  365.     Regs.AL := $09;  {subfunction $09}
  366.     Regs.BL := i;  {drive number}
  367.     MsDos(Regs);
  368.     If (FCarry And Regs.Flags) = 0 Then Drives := Drives + MaxDrives[i];
  369.   End;
  370.   Regs.AX := $0;
  371.   LogicalDrives := Drives;
  372. End{LogicalDrives};
  373.  
  374. { -------------------------------------------------------------------------- }
  375.  
  376. function DriveExists(drive: char) : boolean;
  377. { Original author: Orazio Czerwenka }
  378. var
  379.   s  : string;
  380.   b  : boolean;
  381.   i  : integer;
  382.   ch : char;
  383. begin
  384.   b:= FALSE;
  385.   s:= LogicalDrives;
  386.   i:= 1;
  387.   drive:= upcase(drive);
  388.   while not (i > length(s)) and (b= false) do begin
  389.     b:= (drive= s[i]);
  390.     inc(i);
  391.   end;
  392.   DriveExists:= b;
  393. end;
  394.  
  395. { -------------------------------------------------------------------------- }
  396.  
  397. {
  398.  Changes
  399.  =======
  400.  in 1.00
  401.  -------
  402. 09/06/1994 -ocz The following routines have been implemented from Andrew
  403.                 Eigus' unit ENHDOS:
  404.                 GetVerify, SetVerify, GetCurDisk, SetCurDisk, GetDrive-
  405.                 AllocInfo, GetDPB, DiskSize DiskFree, IsFixedDisk,
  406.                 IsNetworkDrive, IsCDROMDrive, IsCompressedDrive,
  407.                 GetDriveType
  408.            -ocz IsFixedDisk renamed to IsFixedDrive
  409.            -ocz LogicalDrives moved from FDOS.PAS to FDRIVES.DEC/INC.
  410. }